<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/600753 (zh-CN, DDL); Windows/10.0.0 (Win64);"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="1520"/>

<div>
<span><div><span style="font-size: 12px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-caps: normal; font-variant-ligatures: common-ligatures;">本文链接：</span><a href="https://blog.csdn.net/qq_37941471/article/details/80710099" style="outline: 0px; cursor: pointer; overflow-wrap: break-word; font-size: 14px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 153, 234); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-caps: normal; font-variant-ligatures: common-ligatures;">https://blog.csdn.net/qq_37941471/article/details/80710099</a></div><div>直接插入排序</div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">自身的数字从最开始的对比一直是前两位</span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">通过第0位和第一位的进行对比</span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">如果0比1大就交换值</span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">如果是下标4比下标5大</span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">下标4的值覆盖下标5 </span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">下标减一 并且和原本的下标5的值进行对比 </span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">如果大把下标四的值覆盖 此时下标五和下标四都是一样的值 不过下标五的值已经提前赋值给其他变量进行对比</span></div><div><span style="font-size: 9pt;"><br/></span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">如果判断没有之后的大于前一位</span></div><div><span style="font-size: 9pt; color: rgb(51, 51, 51); font-family: Monaco;">就退出并且加加把下标五的值赋值给当前的 </span></div><div><span style="font-size: 9pt;"><br/></span></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div>int main()</div><div>{</div><div>        //test();</div><div>        //return 0;</div><div>        int a[] = { 9,8,7,6,5,4,3,2,1};</div><div>        int len = sizeof(a) / sizeof(int);</div><div>        for (size_t i = 1; i &lt; len; i++)</div><div>        {</div><div>               int end = i - 1;</div><div>               int tem = a[i];</div><div>               while (end &gt;= 0)</div><div>               {</div><div>                       if (a[end] &gt; tem)</div><div>                       {</div><div>                              a[end + 1] = a[end];</div><div>                              end--;</div><div>                       }</div><div>                       else</div><div>                              break;</div><div>               }</div><div>               a[end + 1] = tem;</div><div>        }</div><div>        for (size_t i = 0; i &lt; len; i++)</div><div>        {</div><div>               cout &lt;&lt; a[i];</div><div>        }</div><div>}</div></div><div>希尔排序</div><div>希尔排序如同直接插入排序 相同</div><div>不同的在于他们是进行+n的</div><div>例如从+5 +3 +1 一次递降的过程 </div><div>实现排序  交换的过程和直插一样</div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div>int main()</div><div>{       //test();</div><div>        //return 0;</div><div>        int a[] = { 9,8,7,6,5,4,3,2,1};</div><div>        int len = sizeof(a) / sizeof(int);</div><div>        int temp = len;</div><div>        </div><div>        while (temp&gt;1)</div><div>        {</div><div>               temp = temp / 3 + 1;</div><div>               for (size_t i = 0; i &lt; len-temp; i++)</div><div>               {</div><div>                       int end = i;</div><div>                       int tem = a[end + temp];</div><div>                       while (end&gt;=0&amp;&amp;a[end]&gt;tem)</div><div>                       {</div><div>                              a[end + temp] = a[end];</div><div>                              end -= temp;</div><div>                       }</div><div>                       a[end + temp] = tem;</div><div>               }</div><div>        }</div><div>        for (size_t i = 0; i &lt; len; i++)</div><div>        {</div><div>               cout &lt;&lt; a[i];</div><div>        }</div><div>  </div><div>}</div></div><div>选择排序<br/></div><div>选择排序的技能思路，在头确定begin设定为最大值最小值</div><div>进行判断每一轮的最值和begin和end进行交换</div><div>注意的是如果在max=begin 时</div><div>min和begin进行交换 那么此时最大值的小标就是min不是begin</div><div>所以把min赋值给max</div><div>再进行和max和end的交换</div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div>int a[] = { 2,5,7,6,4,3,9,0 };</div><div>        int n = sizeof(a) / sizeof(a[0]);</div><div>        int begin = 0;</div><div>        int end = n - 1;</div><div>        while (begin&lt;end)</div><div>        {</div><div>               int max = begin, min = begin;</div><div>               for (size_t i = begin; i &lt;=end; i++)</div><div>               {</div><div>                       if (a[max] &lt; a[i])</div><div>                       {</div><div>                              max = i;</div><div>                       }</div><div>                       if (a[min] &gt; a[i])</div><div>                       {</div><div>                              min = i;</div><div>                       }</div><div>               }</div><div>               swap(a[min], a[begin]);</div><div>               if (max == begin)</div><div>               {</div><div>                       max = min;</div><div>               }</div><div>               swap(a[max], a[end]);</div><div>               begin++;</div><div>               end--;</div><div>        }</div><div>        for (size_t i = 0; i &lt; n; i++)</div><div>        {</div><div>               cout &lt;&lt; a[i];</div><div>        }</div></div><div><br/></div></span>
</div></body></html> 